// 创建一个home数据库

//引入请求函数
import {reqCategoryList,reqRollPlayList,reqFloorList} from '@/api'
// 创建一个actions用来处理数据
const actions = {
    //发送请求获取三级页面数据
    async  getCategoryList({commit}){
        let result = await reqCategoryList()
        if(result.code ===200){
            commit('SAVE_CATEGORY_LIST',result.data.slice(0,15))
        }else{
            alert(result.message)
        }
    },
    async  getRollPlayList({commit}){
            let result = await reqRollPlayList()
            if(result.code ===200){
                commit('SAVE_ROLLPLAY_LIST',result.data)
            }else{
                alert(result.message)
            }
    },
    async  getFloorList({commit}){
    let result = await reqFloorList()
    if(result.code ===200){
        commit('SAVE_FLOOR_LIST',result.data)
    }else{
        alert(result.message)
    }
    }

};
//创建一个mutations 用来改变数据
const mutations = {
    SAVE_CATEGORY_LIST(state,list){
        state.categoryList=list
    },
    SAVE_ROLLPLAY_LIST(state,list){
        state.rollPlayList = list
    },
    SAVE_FLOOR_LIST(state,list){
        state.floorList=list
    }
};
// 创建一个state用来储存数据
const state = {
     categoryList:[],
     rollPlayList:[],
     floorList:[]
};
//创建一个getters用来计算数据
const getters = {};
// 暴露一个仓库
export default {
    actions,
    mutations,
    state,
    getters,
}

